<template>
  <el-dialog
    :title="title"
    :visible.sync="Addzsk"
    width="460px"
    append-to-body
    @close="close"
  >
    <el-form :model="form" label-width="80px">
      <el-form-item label="名称">
        <el-input
          v-model="form.ragsName"
          placeholder="输入知识库名称"
        ></el-input>
      </el-form-item>
     <el-form-item label="描述">
        <el-input
          type="textarea"
          v-model="form.ragsDesc"
          placeholder="请描述知识库内容"
        ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="Addzsk = false">取消</el-button>
      <el-button type="primary" @click="handleConfirm">确认</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: 'AddKnowledgeBase',
  data() {
    return {
      title:'新增知识库',
      Addzsk: false, // 控制弹窗显示隐藏，可根据父组件传值调整
      form: {
        ragsName: '',
        ragsDesc: ''
      }
    }
  },
  methods: {
    open(row) {
     this.Addzsk = true
      if(row){
        this.title='编辑知识库'
        this.form.id = row.id
        this.form.ragsName = row.ragsName
        this.form.ragsDesc = row.ragsDesc
      }else{
          this.title='新增知识库'
      }
    },
    close() {
      this.form.ragsName = ''
      this.form.ragsDesc = ''
    },
    handleConfirm() {
      if(this.form.ragsName.trim()==''){
           this.$message.error('请输入知识库名称');
        return
      }
      let params = {
        // "name": this.form.name
        id: '',
        ...this.form,
        userId: ''
      }
      this.$httpApi.createRags(params).then((res) => {
        if (res.success) {
          this.$message.success('提交成功');
          this.$emit('getRefs')
        }else{
           this.$message.error(res.msg);
        }
      })
      // 若提交成功后关闭弹窗，可根据实际交互调整
      this.Addzsk = false;
    }
  }
}
</script>

<style scoped>
.dialog-footer {
  text-align: right;
}
</style>
